__init__.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. """
  2. pip._vendor is for vendoring dependencies of pip to prevent needing pip to
  3. depend on something external.
  4. Files inside of pip._vendor should be considered immutable and should only be
  5. updated to versions from upstream.
  6. """
  7. from __future__ import absolute_import
  8. import glob
  9. import os.path
  10. import sys
  11. # Downstream redistributors which have debundled our dependencies should also
  12. # patch this value to be true. This will trigger the additional patching
  13. # to cause things like "six" to be available as pip.
  14. DEBUNDLED = False
  15. # By default, look in this directory for a bunch of .whl files which we will
  16. # add to the beginning of sys.path before attempting to import anything. This
  17. # is done to support downstream re-distributors like Debian and Fedora who
  18. # wish to create their own Wheels for our dependencies to aid in debundling.
  19. WHEEL_DIR = os.path.abspath(os.path.dirname(__file__))
  20. # Define a small helper function to alias our vendored modules to the real ones
  21. # if the vendored ones do not exist. This idea of this was taken from
  22. # https://github.com/kennethreitz/requests/pull/2567.
  23. def vendored(modulename):
  24. vendored_name = "{0}.{1}".format(__name__, modulename)
  25. try:
  26. __import__(modulename, globals(), locals(), level=0)
  27. except ImportError:
  28. # This error used to be silenced in earlier variants of this file, to instead
  29. # raise the error when pip actually tries to use the missing module.
  30. # Based on inputs in #5354, this was changed to explicitly raise the error.
  31. # Re-raising the exception without modifying it is an intentional choice.
  32. raise
  33. else:
  34. sys.modules[vendored_name] = sys.modules[modulename]
  35. base, head = vendored_name.rsplit(".", 1)
  36. setattr(sys.modules[base], head, sys.modules[modulename])
  37. # If we're operating in a debundled setup, then we want to go ahead and trigger
  38. # the aliasing of our vendored libraries as well as looking for wheels to add
  39. # to our sys.path. This will cause all of this code to be a no-op typically
  40. # however downstream redistributors can enable it in a consistent way across
  41. # all platforms.
  42. if DEBUNDLED:
  43. # Actually look inside of WHEEL_DIR to find .whl files and add them to the
  44. # front of our sys.path.
  45. sys.path[:] = glob.glob(os.path.join(WHEEL_DIR, "*.whl")) + sys.path
  46. # Actually alias all of our vendored dependencies.
  47. vendored("appdirs")
  48. vendored("cachecontrol")
  49. vendored("certifi")
  50. vendored("colorama")
  51. vendored("contextlib2")
  52. vendored("distlib")
  53. vendored("distro")
  54. vendored("html5lib")
  55. vendored("six")
  56. vendored("six.moves")
  57. vendored("six.moves.urllib")
  58. vendored("six.moves.urllib.parse")
  59. vendored("packaging")
  60. vendored("packaging.version")
  61. vendored("packaging.specifiers")
  62. vendored("pep517")
  63. vendored("pkg_resources")
  64. vendored("progress")
  65. vendored("retrying")
  66. vendored("requests")
  67. vendored("requests.exceptions")
  68. vendored("requests.packages")
  69. vendored("requests.packages.urllib3")
  70. vendored("requests.packages.urllib3._collections")
  71. vendored("requests.packages.urllib3.connection")
  72. vendored("requests.packages.urllib3.connectionpool")
  73. vendored("requests.packages.urllib3.contrib")
  74. vendored("requests.packages.urllib3.contrib.ntlmpool")
  75. vendored("requests.packages.urllib3.contrib.pyopenssl")
  76. vendored("requests.packages.urllib3.exceptions")
  77. vendored("requests.packages.urllib3.fields")
  78. vendored("requests.packages.urllib3.filepost")
  79. vendored("requests.packages.urllib3.packages")
  80. vendored("requests.packages.urllib3.packages.ordered_dict")
  81. vendored("requests.packages.urllib3.packages.six")
  82. vendored("requests.packages.urllib3.packages.ssl_match_hostname")
  83. vendored("requests.packages.urllib3.packages.ssl_match_hostname."
  84. "_implementation")
  85. vendored("requests.packages.urllib3.poolmanager")
  86. vendored("requests.packages.urllib3.request")
  87. vendored("requests.packages.urllib3.response")
  88. vendored("requests.packages.urllib3.util")
  89. vendored("requests.packages.urllib3.util.connection")
  90. vendored("requests.packages.urllib3.util.request")
  91. vendored("requests.packages.urllib3.util.response")
  92. vendored("requests.packages.urllib3.util.retry")
  93. vendored("requests.packages.urllib3.util.ssl_")
  94. vendored("requests.packages.urllib3.util.timeout")
  95. vendored("requests.packages.urllib3.util.url")
  96. vendored("resolvelib")
  97. vendored("toml")
  98. vendored("toml.encoder")
  99. vendored("toml.decoder")
  100. vendored("urllib3")